package org.tity.test.data;

import java.util.Arrays;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.tity.sql.GlobalSettings;
import org.tity.sql.dao.DAO;
import org.tity.sql.data.DataNameFormat;
import org.tity.sql.data.RcdSet;
import org.tity.test.config.AppDAO;
import org.tity.test.config.Configs;

public class ToJSON {

	private DAO dao;

	@Before
	public void setUp() throws Exception {

		Configs config = new Configs();
		dao = new AppDAO();
		dao.setDataSource(config.getDataSource());
		
		/*
		 * 设置全局的转换参数
		 * DataNameCaseType.NONE  不转换，与数据库查询字段名一致
		 * DataNameCaseType.UPPER_CASE  转为大写
		 * DataNameCaseType.LOWER_CASE 转为小写
		 * */
		GlobalSettings.DEFAULT_DATA_NAME_FORMAT=DataNameFormat.NONE;
		
	}

	@Test
	public void out() {
		RcdSet rs = dao.query("select * from json_test");
		
		List<String> excludeFields=Arrays.asList("id","code");
		List<String> includeFields=Arrays.asList("NAME","id");
		//所有字段
		System.out.println("ALL:"+rs.toJSONArrayWithJSONObject());
		//指定需要包含的字段
		System.out.println("INCLUDE-A"+rs.toJSONArrayWithJSONObject("id","code"));
		
		//指定需要包含的字段
		System.out.println("INCLUDE-B"+rs.toJSONArrayWithJSONObject(includeFields,null));
		//仅指定排除的字段
		System.out.println("EX-"+rs.toJSONArrayWithJSONObject(null,excludeFields));
		
		//同时指定包含的字段和排除的字段
		System.out.println("IN_EX"+rs.toJSONArrayWithJSONObject(includeFields,excludeFields));
		
	}
 
}
